package com.xj.admin.bussiness.reference.web;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;

import com.xj.admin.base.index.web.BaseController;
import com.xj.admin.bussiness.reference.service.YzUserMachinReferenceService;

import com.xj.common.base.common.bean.AbstractBean;
import com.xj.common.bussiness.reference.entity.YzUserMachinReference;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 *   前端控制器
 * </p>
 *
 * @author Mars
 * @since 2017-08-24
 */
@RestController
@Slf4j
@RequestMapping("yzUserMachinReference")
public class YzUserMachinReferenceController extends BaseController {
	
	@Autowired
	private YzUserMachinReferenceService yzUserMachinReferenceService;
	@GetMapping("/list.auth")
	public AbstractBean yzUserMachinReferenceList(@RequestParam(required=false,defaultValue="0") Integer pageNum,@RequestParam(required=false,defaultValue="10") Integer pageSize){
		return json(yzUserMachinReferenceService.selectMapsPage(new Page<YzUserMachinReference>(pageNum, pageSize), new EntityWrapper<YzUserMachinReference>()));
	}
	
	@GetMapping("/{phone}.auth")
	public AbstractBean yzuserContent(@PathVariable Integer id){
		return json(yzUserMachinReferenceService.selectOne(new EntityWrapper<YzUserMachinReference>().eq("id", id)));
	}
	
	@GetMapping("/findReferenceByIdCardNumList")
	public AbstractBean findReferenceByIdCardNumList(@RequestParam String idCardNum){
		return json(yzUserMachinReferenceService.findReferenceByIdCardNum(idCardNum));
	}
	
	@GetMapping("/findReferenceByIdCardNumV2")
	public AbstractBean findReferenceByIdCardNumV2(@RequestParam String idCardNum){
		return json(yzUserMachinReferenceService.findReferenceByIdCardNumV2(idCardNum));
	}
	
	
	@PostMapping("/save")
	public AbstractBean add(YzUserMachinReference yzUserMachinReference){		
		if(!yzUserMachinReferenceService.insert(yzUserMachinReference)){
		return error();
	    }
		return success();
	}
	
	@PostMapping("/update")
	public AbstractBean update(YzUserMachinReference yzUserMachinReference){		
		if(!yzUserMachinReferenceService.updateById(yzUserMachinReference)){
		return error();
	    }
		return success();
	}
	
	

	
	
	@DeleteMapping("{id}/delete")
    public AbstractBean delete(@PathVariable(required=true) Integer id) {	
		if(!yzUserMachinReferenceService.deleteById(id)){
		return error();
		}
		return success();
    }
}
